//
//  MainDetailTopScrollView.m
//  ZITHER
//
//  Created by weixin on 2018/8/15.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "MainDetailTopScrollView.h"

@implementation MainDetailTopScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.bounces = NO;
        self.showsHorizontalScrollIndicator = NO;
        self.contentSize = CGSizeMake(kScreenW*2,0);
        self.contentOffset = CGPointMake(kScreenW, 0);
        self.bounces = NO; // 默认为YES 取消设置NO
        // 当bounces属性为NO时，以下两个属性设置无效
        self.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
        self.alwaysBounceVertical = YES; // 垂直方向弹簧效果
        self.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
        self.pagingEnabled = YES; // 默认为NO，设置YES内容视图整页滚动
        self.delegate = self;
        self.backgroundColor = [UIColor whiteColor];
        [self setUI];
        
    }
    return self;
}


-(void)typeTwoPage{
    CGFloat x = SCREEN_WIDTH;
    for (int i = 0; i<2; i++) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(x, 100*i, kScreenW, 100)];
        [self addSubview:view];
        
        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 30, 20, 20)];
        if (i == 0) {
            imageV.image = [UIImage imageNamed:@"sku_icon_brand"];
        }else{
            imageV.image = [UIImage imageNamed:@"sku_icon_serise"];
        }
        imageV.contentMode = 2;
        [view addSubview:imageV];
        
        if (i==0) {
            self.brandName = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV.frame)+15, 10, kScreenW-90, 25)];
            self.brandName.text = @"Vacheron Constantin";
            self.brandName.centerY = imageV.centerY-10;
            
            self.brandName.font = [UIFont systemFontOfSize:25];
            [view addSubview: self.brandName];
            
            
            self.brandNameNative = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV.frame)+15, 30, kScreenW-90, 15)];
            self.brandNameNative.text = @"江诗丹顿/康斯坦丁";
            self.brandNameNative.font = [UIFont systemFontOfSize:15];
            self.brandNameNative.centerY = imageV.centerY+10;
            
            [view addSubview: self.brandNameNative];
            
        } else {
            self.seriesName = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV.frame)+15, 10, kScreenW-90, 25)];
            self.seriesName.text = @"Vacheron Constantin";
            self.seriesName.centerY = imageV.centerY-10;
            
            self.seriesName.font = [UIFont systemFontOfSize:25];
            [view addSubview:self.seriesName];
            
            
            self.seriesNameNative = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imageV.frame)+15, 30, kScreenW-90, 15)];
            self.seriesNameNative.text = @"江诗丹顿/康斯坦丁";
            self.seriesNameNative.font = [UIFont systemFontOfSize:15];
            self.seriesNameNative.centerY = imageV.centerY+10;
            
            [view addSubview:self.seriesNameNative];
        }
        UIImageView *imageV2= [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-40, 30, 30, 30)];
        imageV2.image = [UIImage imageNamed:@"sku_btn_into"];
        [view addSubview:imageV2];
    }
}


-(void)setUI{
    [self addSubview:self.imageV];
    [self addSubview:self.tbvTitle];
    [self typeTwoPage];
}

-(UIImageView *)imageV{
    if (!_imageV) {
        _imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW,kScreenW)];
        _imageV.backgroundColor = [UIColor whiteColor];
        _imageV.contentMode = UIViewContentModeScaleAspectFill;
        _imageV.image = [UIImage imageNamed:@"watchImage"];
        _imageV.clipsToBounds = YES;
        _imageV.contentMode = 1;
    }
    return  _imageV;
}

-(MainDetailTopPropertyTbv *)tbvTitle{
    if (!_tbvTitle) {
        _tbvTitle = [[MainDetailTopPropertyTbv alloc]initWithFrame:CGRectMake(kScreenW*2,0 , kScreenW,SCREEN_WIDTH-30)];
    }
    return  _tbvTitle;
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [self changePage:0];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH){
        [self changePage:1];
    }else if (scrollView.contentOffset.x == SCREEN_WIDTH*2){
        [self changePage:2];
    }
    
}


-(void)changePage:(int)index{
//    SKUDetailNewVc *vc  = (SKUDetailNewVc*)[self getViewController:[SKUDetailNewVc class]];
//    SKUDetailWatchScrNewV *sc1 = vc.scrBasepParent.DetailWatchScr;
//    [UIView animateWithDuration:0.1 animations:^{
//        self.pageController.currentPage = index;
//        CGRect frame = self.pageController.frame;
//        CGRect frame2 = self.frame;
//      
//        if (index ==1) {
//            frame.origin.y =200;
//            frame2.size.height = 200;
//            sc1.contentSize = CGSizeMake(0, 1300);
//        }else{
//            frame.origin.y = SCREEN_WIDTH-30;
//            frame2.size.height = SCREEN_WIDTH-30;
//            sc1.contentSize = CGSizeMake(0, 1480);
//        }
//        
//        self.pageController.frame = frame;
//        self.frame = frame2;
//        sc1.UserImageS.frame = CGRectMake(0, CGRectGetMaxY(sc1.TopscroView.frame)+20, kScreenW, 200);
//        sc1.ScrPublicV.frame = CGRectMake(15, CGRectGetMaxY(sc1.UserImageS.frame)+60, kScreenW-30, sc1.ScrPublicV.frame.size.height);
//        sc1.GraphV.frame = CGRectMake(0, CGRectGetMaxY(sc1.ScrPublicV.frame), kScreenW, 600);
//    }];
}


-(UIPageControl *)pageController
{
    if (!_pageController) {
        _pageController = [[UIPageControl alloc] initWithFrame:CGRectMake(0,200 , 80, 30)];
        _pageController.centerX = self.centerX;
        _pageController.numberOfPages = 2;
        _pageController.currentPage = 1;//滑动是修改显示
        _pageController.currentPageIndicatorTintColor = [UIColor blackColor];
        _pageController.pageIndicatorTintColor = [UIColor RGBColorWithR:224 g:224 b:224];
    }
    return _pageController;
}

-(UILabel *)brandName{
    if (!_brandName) {
        _brandName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        
    }
    return _brandName;
}

-(UILabel *)brandNameNative{
    if (!_brandNameNative) {
        _brandNameNative = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        
    }
    return _brandNameNative;
}

-(UILabel *)seriesName{
    if (!_seriesName) {
        _seriesName = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
        
    }
    return _seriesName;
}

-(UILabel *)seriesNameNative{
    if (!_seriesNameNative) {
        _seriesNameNative = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
    }
    return _seriesNameNative;
}

@end
